package com.hz.pay.center.service.strategy.impl;

import com.pay.common.enums.PayWayEnum;
import com.hz.pay.center.exception.BizException;
import com.hz.pay.center.factory.PayFactory;
import com.hz.pay.center.model.PaySerialInfo;
import com.pay.common.resp.NetBankPayRespData;
import com.hz.pay.center.service.strategy.IStrategyPayService;
import com.hz.pay.center.utils.AlipayUtils;
import com.hz.pay.center.vo.PayVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 支付宝扫码支付的实现类
 */
@Service
public class AliapyQrCodeStrategyPayServiceImpl implements IStrategyPayService, InitializingBean {


    @Autowired
    private AlipayUtils alipayUtils;

    private Logger logger = LoggerFactory.getLogger(AliapyQrCodeStrategyPayServiceImpl.class);


    /**
     *  支付宝扫码支付的实现 调用支付宝的接口
     * @param paySerialInfo
     * @return
     * @throws BizException
     */
    @Override
    public NetBankPayRespData payment(PaySerialInfo paySerialInfo) throws BizException{
        NetBankPayRespData payRespData = new NetBankPayRespData();
        PayVo payVo = new PayVo();
        payVo.setOutTradeNo(paySerialInfo.getPaySerialNo());
        payVo.setSubject(paySerialInfo.getOrderDesc());
        payVo.setTotalAmount(paySerialInfo.getPayAmount());


        String qrCode = alipayUtils.alipayQrCodePay(payVo);
        payRespData.setMchId(paySerialInfo.getMchId());
        payRespData.setPaySerialNo(paySerialInfo.getPaySerialNo());
        payRespData.setPayUrl(qrCode);
        //封装对象
        return payRespData;

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info("-------初始化AliapyQrCodeStrategyPayServiceImpl--------");
        PayFactory.concurrentHashMap.put(PayWayEnum.ALIPAY_QRCODE_PAY.getCode(),this);

    }
}
